cc.Class({
    extends: cc.Component,

    properties: {
        scoreDisplay: {
            default: null,
            type: cc.Label
        },
		targetDisplay: {
            default: null,
            type: cc.Label
        },
		stepDisplay: {
            default: null,
            type: cc.Label
        },
		levelDisplay: {
            default: null,
            type: cc.Label
        },
		hummerDisplay: {
            default: null,
            type: cc.Label
        },
		magicDisplay: {
            default: null,
            type: cc.Label
        },
		game: {
            default: null,
            type: cc.Node
        },
    },

    onLoad () {
		
		this.score = 0;
		this.level =0;
		this.target=0;
		this.level=0;
		this.complete=0;
		this.hummerNmb = 0;
		this.magicNmb = 0;
		
		this.node.on(cc.Node.EventType.TOUCH_START,function(event){
			
			var tx = event.getLocationX(),ty = event.getLocationY();
			
			var game = this.game.getComponent('GameByChapter');
			
			var width = game.width;
			
			if(tx>=width/4-30&&tx<=width/4+30&&ty>=50&&ty<=110){
				
				//console.log("hummer");
				if(game.gameManager.canTouchStart())
					game.useHummer();
				
				return ;
			}
			
			if(tx>=width*3/4-30&&tx<=width*3/4+30&&ty>=50&&ty<=110){
				
				//console.log("magic");
				if(game.gameManager.canTouchStart())
					game.useMagic();
				
				return ;
			}
			
		}.bind(this));
	},


    update (dt) {
		if(this.game.getComponent('GameByChapter').getScore()!=this.score){
			//console.log('change score');
			this.score = this.game.getComponent('GameByChapter').getScore();
			this.scoreDisplay.string = '得分:'+this.score;
		}
		
		if(this.game.getComponent('GameByChapter').getStep()!=this.step){
			//console.log('change step');
			this.step = this.game.getComponent('GameByChapter').getStep();
			this.stepDisplay.string = '步数:'+this.step;
		}
		
		
		if(
			this.game.getComponent('GameByChapter').getTarget()!=this.target
			||this.game.getComponent('GameByChapter').getComplete()!=this.complete
			){
			//console.log('change target');
			this.target = this.game.getComponent('GameByChapter').getTarget();
			this.complete = this.game.getComponent('GameByChapter').getComplete();
			this.targetDisplay.string = this.complete+ '/'+this.target;
		}
		
		if(this.game.getComponent('GameByChapter').getLevel()!=this.level){
			//console.log('change level');
			this.level = this.game.getComponent('GameByChapter').getLevel();
			this.levelDisplay.string = '关卡:'+(this.level+1);
		}
		
		if(this.game.getComponent('GameByChapter').hummerNmb!=this.hummerNmb){
			//console.log('change level');
			this.hummerNmb = this.game.getComponent('GameByChapter').hummerNmb;
			this.hummerDisplay.string = 'x'+this.hummerNmb;
		}
		
		if(this.game.getComponent('GameByChapter').magicNmb!=this.magicNmb){
			//console.log('change level');
			this.magicNmb = this.game.getComponent('GameByChapter').magicNmb;
			this.magicDisplay.string = 'x'+this.magicNmb;
		}
		
	},
});
